package com.daji.search_and_sort;

import java.util.Arrays;


/* 
 * 冒泡排序
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = { 7, 6, 12, -11, 5, 12, 0, 3, 7, 20 };
        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    private static void bubbleSort(int[] arr) {

       for (int i = arr.length - 1; i >= 0; i--) {
        int max = arr[i];
        for (int j = 0; j < i; j++) {
            if(arr[j] > max){
                max = arr[j];
                swop(arr, i, j);
            }

        }
       }
        
        
    }

    private static void swop(int[] arr, int i, int minIndex) {
        int temp = arr[i];
        arr[i] = arr[minIndex];
        arr[minIndex] = temp;
    }
}
